﻿using UnityEngine;
using System.Collections.Generic;
using System;

public class Info : Akequ.Plugins.PluginInfo
{
    public override string Name => "Test Plugin";

    public override string Id => "com.akequ.test";

    public override string Version => "1";

    public override ushort BundleVersion => 1;

    public Info() { }
}


namespace Plugin.Additional
{
    public class TestCommunication : Akequ.Base.Room
    {
        GameObject eventObj = new GameObject();
        public override void Init()
        {
            if (netEvent.isServer)
            {
                Log("服务端已开启，正在记录ing");

                HookManager.Add(eventObj, "onSupportSpawned", (obj) =>
                {
                    Log("已产生的支援为：" + obj[0].ToString());
                });

                HookManager.Add(eventObj, "onSupportApproved", (obj) =>
                {
                    Log("下一次的支援时间为：" + obj[0].ToString());
                });
                HookManager.Add(eventObj, "onPlayerConnected", (obj) =>
                {
                    Player player = PlayerUtilities.GetServerPlayer((Mirror.NetworkConnectionToClient)obj[0]);
                    Log($"[{player.accountUID}][{player.accountName}]加入了游戏");
                });
                HookManager.Add(eventObj, "onClassDEscape", (obj) =>
                {
                    Player player = (Player)obj[0];
                    Log($"[{player.accountUID}][{player.accountName}]DD逃离了设施");
                });
                HookManager.Add(eventObj, "onScientistEscape", (obj) =>
                {
                    Player player = (Player)obj[0];
                    Log($"[{player.accountUID}][{player.accountName}]科学家逃离了设施");
                });
                HookManager.Add(eventObj, "onPlayerDeath", (obj) =>
                {
                    DamageHandler damage = (DamageHandler)obj[1];
                    Player player = (Player)obj[0];
                    Log($"[{player.accountUID}][{player.accountName}]死亡 来自于[{damage.killer}][原因 {damage.deathReason}][伤害 {damage.damage}]");
                });
                HookManager.Add(eventObj, "onRoundStart", (obj) =>
                {
                    Player[] players = GameObject.FindObjectsOfType<Player>();
                    Log($"新的回合已开始，参与人数：{players.Length}");
                });
                HookManager.Add(eventObj, "onRoundEnd", (obj) =>
                {
                    Player[] players = GameObject.FindObjectsOfType<Player>();
                    Log($"回合已结束，参与人数：{players.Length}");
                });


            }
        }

        public void Log(string text)
        {
            Debug.Log($"{DateTime.Now.ToLongTimeString().ToString()} [INFO]{text}");
        }
    }
}